<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\form\util\control;

/**
 * 区间控件
 * @author cleverstone
 * @since ym2.0
 */
class Section extends Control
{
    /**
     * @var array
     */
    private $_options = [
        'control' => 'section',
        'label' => '',
        'placeholder' => ['请输入', '请输入'],
        'default' => ['', ''],
        'required' => false,
        'comment' => '',
        'help' => '',
        'layout' => 12,
        'firstStyle' => '',
        'lastStyle' => '',
        'class' => '',
        'firstAttribute' => '',
        'lastAttribute' => '',
    ];

    /**
     * 控件标签
     * @param string|null $label
     * @return $this
     */
    public function label($label)
    {
        $this->_options['label'] = $label;
        return $this;
    }

    /**
     * 站位文本
     * @param string $range1 区间1
     * @param string $range2 区间2
     * @return $this
     */
    public function placeholder($range1, $range2)
    {
        $this->_options['placeholder'] = [(string)$range1, (string)$range2];
        return $this;
    }

    /**
     * 默认值
     * @param string $range1 区间1
     * @param string $range2 区间2
     * @return $this
     */
    public function defaultValue($range1, $range2)
    {
        $this->_options['default'] = [(string)$range1, (string)$range2];
        return $this;
    }

    /**
     * 是否必填
     * @param bool $required
     * @return $this
     */
    public function required($required = true)
    {
        $this->_options['required'] = (boolean)$required;
        return $this;
    }

    /**
     * 字段注释
     * @param string $comment
     * @return $this
     */
    public function comment($comment)
    {
        $this->_options['comment'] = (string)$comment;
        return $this;
    }

    /**
     * 帮助文字
     * @param string $help
     * @return $this
     */
    public function help($help)
    {
        $this->_options['help'] = (string)$help;
        return $this;
    }

    /**
     * 布局，1-12
     * @param int $layout
     * @return $this
     */
    public function layout($layout)
    {
        $this->_options['layout'] = (int)$layout;
        return $this;
    }

    /**
     * 区间1 CSS样式
     * @param array|string $style
     * @return $this
     */
    public function firstStyle($style)
    {
        $this->formatStyle($style);
        $this->_options['firstStyle'] = $style;

        return $this;
    }

    /**
     * 区间2 CSS样式
     * @param array|string $style
     * @return $this
     */
    public function lastStyle($style)
    {
        $this->formatStyle($style);
        $this->_options['lastStyle'] = $style;

        return $this;
    }

    /**
     * UI
     * @param array|string $class
     * @return $this
     */
    public function uiClass($class)
    {
        $this->formatUiClass($class);
        $this->_options['class'] = $class;

        return $this;
    }

    /**
     * 区间1 HTML属性
     * @param array|string $attribute
     * @return $this
     */
    public function firstAttribute($attribute)
    {
        $this->formatHtmlAttribute($attribute);
        $this->_options['firstAttribute'] = $attribute;

        return $this;
    }

    /**
     * 区间2 HTML属性
     * @param array|string $attribute
     * @return $this
     */
    public function lastAttribute($attribute)
    {
        $this->formatHtmlAttribute($attribute);
        $this->_options['lastAttribute'] = $attribute;

        return $this;
    }

    /**
     * @return array
     */
    public function _toArray()
    {
        return $this->_options;
    }
}